package com.alipay.sofa.award.common.dal.dao;

import com.alipay.sofa.award.common.dal.dataobject.Award;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface AwardMapper {

    int deleteByPrimaryKey(Integer id);

    int deleteByActivityTime(String activityTime);

    int insert(Award record);

    Award selectByPrimaryKey(Integer id);

    Award selectByActivityTimeAndRank(@Param("activityTime") String activityTime,
                                      @Param("rank") String rank);

    int updateByPrimaryKey(Award record);

    int updateByActivityTimeAndRank(Award record);

    int updateActivityTime(@Param("oldActivityTime") String oldActivityTime,
                           @Param("updatedActivityTime") String updatedActivityTime);

    /***
     * Try to win the lottery
     * @param activityTime activityTime
     * @param rank level
     * @param awardCount original award count
     * @return result > 0 then success and win the lottery
     */
    int minusAwardCountByActivityTimeRank(@Param("activityTime") String activityTime,
                                          @Param("rank") String rank,
                                          @Param("awardCount") int awardCount);

    int updateAwardByRankWithSameCount(Award record);
}